/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import DAOs.SatellitalImageJpaController;
import Entity.ReforestationZone;
import Entity.SatellitalImage;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.persistence.EntityManagerFactory;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author USUARIO
 */
public class satellitalImageController {
    public SatellitalImage createSatellitalImage(String discriminator){        
            Calendar fecha = Calendar.getInstance();
            discriminator = discriminator.replace('.','-');
            String dir = discriminator + fecha.get(Calendar.DAY_OF_MONTH) + "_"
                    + (fecha.get(Calendar.MONTH)+1) + "_" + fecha.get(Calendar.YEAR) + ".png";
            System.out.println("Images\\" + dir);
            SatellitalImage sateImage = new SatellitalImage();
            sateImage.setDir(dir);
            sateImage.setFecha(fecha);
            return sateImage;
    }
    
    public void createSatellitalImagePng(String discriminator, ReforestationZone zone){
        Calendar fecha = Calendar.getInstance();
        discriminator = discriminator.replace('.','-');
        String dir = discriminator + fecha.get(Calendar.DAY_OF_MONTH) + "_"
                    + (fecha.get(Calendar.MONTH)+1) + "_" + fecha.get(Calendar.YEAR) + ".png";
        File file = new File("Images\\"+dir);
        GetGoogleMap ggm = new GetGoogleMap();
        System.out.println("zoom: " + zone.getZoom());
        System.out.println("longitude: " + zone.getLongitude());
        System.out.println("latitude: " + zone.getLatitude());
        Image image = ggm.GetMap(String.valueOf(zone.getLatitude()), String.valueOf(zone.getLongitude()), String.valueOf(zone.getZoom()));
        try {
            ImageIO.write((BufferedImage)image, "png", file);
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(new JFrame(), "No se pudo guardar la Imagen", "Error", JOptionPane.ERROR_MESSAGE);
        }
   }
}
